package com.community.web.user.controller.notice;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.community.common.login.LoginUserHolder;
import com.community.common.result.Result;
import com.community.model.entity.Notice;
import com.community.web.user.service.NoticeService;
import com.community.web.user.vo.NoticeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "通知模块")
@RestController
@RequestMapping("/user/notice")
public class NoticeController {
    @Autowired
    private NoticeService service;

    @ApiOperation("分页查询通知列表")
    @GetMapping("{current}/{size}")
    public Result<IPage<NoticeVo>> pageNotice(@PathVariable long current, @PathVariable long size){
        Page<NoticeVo> page = new Page<>(current, size);
        Long userId = LoginUserHolder.getLoginUser().getUserId();
        IPage<NoticeVo> list = service.pageList(userId, page);
        return Result.ok(list);
    }

    @ApiOperation("根据通知id获取详情")
    @GetMapping("{id}")
    public Result<Notice> getNoticeDetail(@PathVariable long id){
        Long userId = LoginUserHolder.getLoginUser().getUserId();
        Notice result = service.getNoticeDetail(id,userId);
        return Result.ok(result);
    }
}
